package com.jsgt.greekfire.repository

import com.jsgt.greekfire.bean.BroadcastTransactionBean
import com.jsgt.greekfire.bean.DelegateAccountBean
import com.jsgt.greekfire.bean.EntrustBean
import com.jsgt.greekfire.bean.UndelegateAccountBean
import com.jsgt.greekfire.common.http.ResponseData
import com.jsgt.greekfire.common.http.RetrofitManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.MediaType
import okhttp3.RequestBody

class EntrustRepository : BaseRepository() {
    companion object {
        val instance = EntrustRepository()
    }

    /**
     * 委托列表
     */
    suspend fun getDelegateList(visible: String): ResponseData<List<EntrustBean>> =
        withContext(Dispatchers.IO) {
            RetrofitManager.entrustService.getDelegateList(visible)
        }

    /**
     * 委托挖矿
     */
    suspend fun delegateaccount(params: String): DelegateAccountBean =
        withContext(Dispatchers.IO) {
            RetrofitManager.entrustService.delegateaccount(RequestBody.create(MediaType.get("application/json; charset=UTF-8"),params))
        }


    /**
     * 广播签名后的交易
     */
    suspend fun broadcasttransaction(params: String): BroadcastTransactionBean =
        withContext(Dispatchers.IO) {
            RetrofitManager.entrustService.broadcasttransaction(RequestBody.create(MediaType.get("application/json; charset=UTF-8"),params))
        }
    /**
     * 取消委托
     */
    suspend fun undelegateaccount(params: String): UndelegateAccountBean =
        withContext(Dispatchers.IO) {
            RetrofitManager.entrustService.undelegateaccount(RequestBody.create(MediaType.get("application/json; charset=UTF-8"),params))
        }
}